﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using DevExpress.XtraEditors;
using SchoolManagementSystem.Controls;
using SchoolManagementSystem.Details;
using CoreData;

namespace SchoolManagementSystem.Forms.BusinessForm
{
    public partial class Stock_ReportForm : DevExpress.XtraEditors.XtraForm
    {
        public Stock_ReportForm()
        {
            InitializeComponent();

            comboboxUC_Stock.Model = RegisterService.RegisterServices.ProductWareHouseService;
            comboboxUC_Stock.Uc = new StockUC();
            comboboxUC_Stock.ColumnMain = "Name";
            comboboxUC_Stock.ColumnDisplay = "Code,Name";
            comboboxUC_Stock.SelectedValue = "1";

            comboboxUC_ProductGroup.Model = RegisterService.RegisterServices.ProductGroupService;
            comboboxUC_ProductGroup.Uc = new Product_GroupUC();
            comboboxUC_ProductGroup.ColumnMain = "Name";
            comboboxUC_ProductGroup.ColumnDisplay = "Code,Name";


            //LoadListStock();
        }
        void LoadListStock()
        {
            var model = RegisterService.RegisterServices.ProductService;
            Product data = new Product();
            data.Product_GroupID = comboboxUC_ProductGroup.ID;
            data.Code = txtProductCode.Text;
            data.Name = txtProductName.Text;

            gridControl1.DataSource = model.GetProductList_StockReport(data);
            gridControl1.RefreshDataSource();
            bandedGridView1.ViewCaption = "Danh sách có " + bandedGridView1.RowCount + " dòng";
            bandedGridView1.ExpandAllGroups();
            bandedGridView1.FocusedRowHandle = -1;
        }

        private void bandedGridView1_SelectionChanged(object sender, DevExpress.Data.SelectionChangedEventArgs e)
        {
            //txtNameStockDetail.Text = bandedGridView1.GetFocusedRowCellValue("Name").ToString();
        }

        private void bandedGridView1_FocusedRowChanged(object sender, DevExpress.XtraGrid.Views.Base.FocusedRowChangedEventArgs e)
        {
            
            //txtNameStockDetail.Text = bandedGridView1.GetFocusedRowCellValue("Name").ToString();
            //txtDetailCode.Text = bandedGridView1.GetFocusedRowCellValue("Code").ToString();
            //txtDetailUnitName.Text = bandedGridView1.GetFocusedRowCellValue("UnitNameExt").ToString();

            //long ProductId = (long)bandedGridView1.GetFocusedRowCellValue("ID");
            //gridControl2.DataSource = null;
            //var model = RegisterService.RegisterServices.ProductService.GetProductDetail_StockReport(ProductId);
            //gridControl2.DataSource = model;
            //gridControl2.RefreshDataSource();
            //bandedGridView2.ViewCaption = "Danh sách có " + bandedGridView1.RowCount + " dòng";
            //bandedGridView2.ExpandAllGroups();

        }

        private void bandedGridView1_RowClick(object sender, DevExpress.XtraGrid.Views.Grid.RowClickEventArgs e)
        {
            txtNameStockDetail.Text = bandedGridView1.GetRowCellValue(e.RowHandle, "Name").ToString();
            txtDetailCode.Text = bandedGridView1.GetRowCellValue(e.RowHandle, "Code").ToString();
            txtDetailUnitName.Text = bandedGridView1.GetRowCellValue(e.RowHandle, "UnitNameExt").ToString();

            long ProductId = (long)bandedGridView1.GetRowCellValue(e.RowHandle, "ID");
            //gridControl2.DataSource = null;
            var model = RegisterService.RegisterServices.ProductService.GetProductDetail_StockReport(ProductId);
            gridControl2.DataSource = model;
            gridControl2.RefreshDataSource();
            bandedGridView2.ViewCaption = "Danh sách có " + bandedGridView1.RowCount + " dòng";
            bandedGridView2.ExpandAllGroups();
        }
        private void cmdFilter_Click(object sender, EventArgs e)
        {
            LoadListStock();
        }
    }
}